import axios from 'axios'
import qs from 'qs'
import router from '@/router'
import { Message } from 'element-ui'



// 添加一个响应拦截器
axios.interceptors.response.use(response => {
  return new Promise((resolve, reject) => {
    if (response.data.code === '000000') {
      resolve(response.data.data)
    } else if (response.data.code === '000100') {
      router.push('/login')
      reject(response.data)
    } else if (response.data.code === '500') {
      Message.error('系统错误')
      reject(response.data)
    } else {
      reject(response.data)
    }
  })
}, (error) => {
  console.log(error)
  return Promise.reject({ msg: '系统错误' })
})

export default axios
